<template>
  <!-- // 分配角色 -->
  <div>
    <el-checkbox-group v-model="roleIds">
      <el-checkbox v-for="item in rows" :key="item.id" :label="item.id">{{ item.name }}</el-checkbox>
    </el-checkbox-group>

    <div style="margin-top: 20px; text-align: right">
      <el-button type="primary" @click="hSubmit">确定</el-button>
      <el-button @click="$emit('close')">取消</el-button>
    </div>
  </div>
</template>
<script>
import { getRoles } from '@/api/setting'
import { userInfo } from '@/api/user'
import { assignRoles } from '@/api/employees'
export default {
  props: {
    curId: {
      required: true,
      type: String
    }
  },
  data() {
    return {
      roleIds: [], // 角色id
      rows: []
    }
  },
  created() {
    this.loadRole()
  },
  methods: {
    async hSubmit() {
      await assignRoles({ id: this.curId, roleIds: this.roleIds })
      this.$message.success('修改成功')
      this.$emit('close')
    },
    // 获取角色信息
    async loadRole() {
      const { data: res } = await getRoles({ page: 1, pagesize: 100 })
      // console.log(res)
      this.rows = res.rows
      // 查询用户拥有权限 回填
      const { data: info } = await userInfo(this.curId)
      this.roleIds = info.roleIds
    }
  }
}
</script>
